package cn.wzg.Server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

public class Server {
    private int port;

    public Server(int port) {
        this.port = port;
    }
    public void runserver() throws Exception{
        ServerBootstrap server =new ServerBootstrap().
                group(new NioEventLoopGroup()).
                channel(NioServerSocketChannel.class).
                localAddress(port).
                childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel socketChannel) throws Exception {
                        socketChannel.pipeline().addLast(new HelloServerHandler());
                    }
                });
        server.bind().sync().channel().closeFuture().sync();
    }

    public static void main(String[] args) throws Exception{
        new Server(6666).runserver();
    }
}
